package com.ict.ms.area.service.api.impl;

import org.springframework.stereotype.Service;

import com.ict.ms.area.facade.api.IWeatherService;
import com.ict.ms.area.facade.model.Weather;
import com.ict.ms.area.service.dao.IWeatherDao;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/5/24.
 */
@Service("weatherService")
public class WeatherService  implements  IWeatherService {
    @Resource
    IWeatherDao dao;

    public List<Weather> getweathers() {
        List<Weather> list = null;
        List<Weather> ret = new ArrayList<Weather>();
        try {
            list = dao.getweathers();
        } catch (Exception e) {
            System.out.println("访问数据库错误" + e);
        }
        for (Weather weather : list) {
            Weather weather1 = new Weather();
            if (weather.getWeather().equals("晴")) {
                weather1.setWea_code(1);
            } else if (weather.getWeather().substring(1).equals("雨")) {
                weather1.setWea_code(3);
            } else {
                weather1.setWea_code(2);
            }
            weather1.setHours(weather.getHours());
            weather1.setLatitude(weather.getLatitude());
            weather1.setName(weather.getName());
            weather1.setVisibility(weather.getVisibility());
            weather1.setWind_direction(weather.getWind_direction());
            weather1.setWind_power(weather.getWind_power());
            weather1.setLongitude(weather.getLongitude());
            ret.add(weather1);
        }

        return ret;
    }
}
